
/*
static int Mul8Bit(int a, int b)
{
	int t = a * b + 128;
	return (t + (t >> 8)) >> 8;
}

static void PrepareOptTable(uint8 * Table, const uint8 * expand, int size)
{
	for (int i = 0; i < 256; i++)
	{
		int bestErr = 256;

		for (int min = 0; min < size; min++)
		{
			for (int max = 0; max < size; max++)
			{
				int mine = expand[min];
				int maxe = expand[max];
				int err = abs(maxe + Mul8Bit(mine-maxe, 0x55) - i);

				if (err < bestErr)
				{
					Table[i*2+0] = max;
					Table[i*2+1] = min;
					bestErr = err;
				}
			}
		}
	}
}


void initTables()
{
	uint8 Expand5[32];
	uint8 Expand6[64];

	for(sInt i=0;i<32;i++)
		Expand5[i] = (i<<3)|(i>>2);

	for(sInt i=0;i<64;i++)
		Expand6[i] = (i<<2)|(i>>4);

	PrepareOptTable(OMatch5, Expand5, 32)
	PrepareOptTable(OMatch6, Expand6, 64)
};
*/

#if __CUDACC__
__constant__ unsigned short
#else
const static uint8 
#endif
OMatch5[256][2] =
{
	{0x00, 0x00},
	{0x00, 0x00},
	{0x00, 0x01},
	{0x00, 0x01},
	{0x01, 0x00},
	{0x01, 0x00},
	{0x01, 0x00},
	{0x01, 0x01},
	{0x01, 0x01},
	{0x01, 0x01},
	{0x02, 0x00},
	{0x02, 0x00},
	{0x02, 0x00},
	{0x02, 0x01},
	{0x00, 0x05},
	{0x03, 0x00},
	{0x03, 0x00},
	{0x03, 0x00},
	{0x03, 0x01},
	{0x03, 0x01},
	{0x03, 0x01},
	{0x03, 0x02},
	{0x04, 0x00},
	{0x04, 0x00},
	{0x03, 0x03},
	{0x04, 0x01},
	{0x05, 0x00},
	{0x05, 0x00},
	{0x05, 0x00},
	{0x05, 0x01},
	{0x05, 0x01},
	{0x05, 0x01},
	{0x03, 0x06},
	{0x06, 0x00},
	{0x06, 0x00},
	{0x06, 0x01},
	{0x04, 0x05},
	{0x07, 0x00},
	{0x07, 0x00},
	{0x07, 0x00},
	{0x07, 0x01},
	{0x07, 0x01},
	{0x07, 0x01},
	{0x07, 0x02},
	{0x08, 0x00},
	{0x08, 0x00},
	{0x07, 0x03},
	{0x08, 0x01},
	{0x09, 0x00},
	{0x09, 0x00},
	{0x09, 0x00},
	{0x09, 0x01},
	{0x09, 0x01},
	{0x09, 0x01},
	{0x07, 0x06},
	{0x0A, 0x00},
	{0x0A, 0x00},
	{0x0A, 0x01},
	{0x08, 0x05},
	{0x0B, 0x00},
	{0x0B, 0x00},
	{0x0B, 0x00},
	{0x0B, 0x01},
	{0x0B, 0x01},
	{0x0B, 0x01},
	{0x0B, 0x02},
	{0x0C, 0x00},
	{0x0C, 0x00},
	{0x0B, 0x03},
	{0x0C, 0x01},
	{0x0D, 0x00},
	{0x0D, 0x00},
	{0x0D, 0x00},
	{0x0D, 0x01},
	{0x0D, 0x01},
	{0x0D, 0x01},
	{0x0B, 0x06},
	{0x0E, 0x00},
	{0x0E, 0x00},
	{0x0E, 0x01},
	{0x0C, 0x05},
	{0x0F, 0x00},
	{0x0F, 0x00},
	{0x0F, 0x00},
	{0x0F, 0x01},
	{0x0F, 0x01},
	{0x0F, 0x01},
	{0x0F, 0x02},
	{0x10, 0x00},
	{0x10, 0x00},
	{0x0F, 0x03},
	{0x10, 0x01},
	{0x11, 0x00},
	{0x11, 0x00},
	{0x11, 0x00},
	{0x11, 0x01},
	{0x11, 0x01},
	{0x11, 0x01},
	{0x0F, 0x06},
	{0x12, 0x00},
	{0x12, 0x00},
	{0x12, 0x01},
	{0x10, 0x05},
	{0x13, 0x00},
	{0x13, 0x00},
	{0x13, 0x00},
	{0x13, 0x01},
	{0x13, 0x01},
	{0x13, 0x01},
	{0x13, 0x02},
	{0x14, 0x00},
	{0x14, 0x00},
	{0x13, 0x03},
	{0x14, 0x01},
	{0x15, 0x00},
	{0x15, 0x00},
	{0x15, 0x00},
	{0x15, 0x01},
	{0x15, 0x01},
	{0x15, 0x01},
	{0x13, 0x06},
	{0x16, 0x00},
	{0x16, 0x00},
	{0x16, 0x01},
	{0x14, 0x05},
	{0x17, 0x00},
	{0x17, 0x00},
	{0x17, 0x00},
	{0x17, 0x01},
	{0x17, 0x01},
	{0x17, 0x01},
	{0x17, 0x02},
	{0x18, 0x00},
	{0x18, 0x00},
	{0x17, 0x03},
	{0x18, 0x01},
	{0x19, 0x00},
	{0x19, 0x00},
	{0x19, 0x00},
	{0x19, 0x01},
	{0x19, 0x01},
	{0x19, 0x01},
	{0x17, 0x06},
	{0x1A, 0x00},
	{0x1A, 0x00},
	{0x1A, 0x01},
	{0x18, 0x05},
	{0x1B, 0x00},
	{0x1B, 0x00},
	{0x1B, 0x00},
	{0x1B, 0x01},
	{0x1B, 0x01},
	{0x1B, 0x01},
	{0x1B, 0x02},
	{0x1C, 0x00},
	{0x1C, 0x00},
	{0x1B, 0x03},
	{0x1C, 0x01},
	{0x1D, 0x00},
	{0x1D, 0x00},
	{0x1D, 0x00},
	{0x1D, 0x01},
	{0x1D, 0x01},
	{0x1D, 0x01},
	{0x1B, 0x06},
	{0x1E, 0x00},
	{0x1E, 0x00},
	{0x1E, 0x01},
	{0x1C, 0x05},
	{0x1F, 0x00},
	{0x1F, 0x00},
	{0x1F, 0x00},
	{0x1F, 0x01},
	{0x1F, 0x01},
	{0x1F, 0x01},
	{0x1F, 0x02},
	{0x1E, 0x04},
	{0x1F, 0x03},
	{0x1F, 0x03},
	{0x1C, 0x09},
	{0x1F, 0x04},
	{0x1F, 0x04},
	{0x1F, 0x04},
	{0x1F, 0x05},
	{0x1F, 0x05},
	{0x1F, 0x05},
	{0x1F, 0x06},
	{0x1E, 0x08},
	{0x1F, 0x07},
	{0x1F, 0x07},
	{0x1C, 0x0D},
	{0x1F, 0x08},
	{0x1F, 0x08},
	{0x1F, 0x08},
	{0x1F, 0x09},
	{0x1F, 0x09},
	{0x1F, 0x09},
	{0x1F, 0x0A},
	{0x1E, 0x0C},
	{0x1F, 0x0B},
	{0x1F, 0x0B},
	{0x1C, 0x11},
	{0x1F, 0x0C},
	{0x1F, 0x0C},
	{0x1F, 0x0C},
	{0x1F, 0x0D},
	{0x1F, 0x0D},
	{0x1F, 0x0D},
	{0x1F, 0x0E},
	{0x1E, 0x10},
	{0x1F, 0x0F},
	{0x1F, 0x0F},
	{0x1C, 0x15},
	{0x1F, 0x10},
	{0x1F, 0x10},
	{0x1F, 0x10},
	{0x1F, 0x11},
	{0x1F, 0x11},
	{0x1F, 0x11},
	{0x1F, 0x12},
	{0x1E, 0x14},
	{0x1F, 0x13},
	{0x1F, 0x13},
	{0x1C, 0x19},
	{0x1F, 0x14},
	{0x1F, 0x14},
	{0x1F, 0x14},
	{0x1F, 0x15},
	{0x1F, 0x15},
	{0x1F, 0x15},
	{0x1F, 0x16},
	{0x1E, 0x18},
	{0x1F, 0x17},
	{0x1F, 0x17},
	{0x1C, 0x1D},
	{0x1F, 0x18},
	{0x1F, 0x18},
	{0x1F, 0x18},
	{0x1F, 0x19},
	{0x1F, 0x19},
	{0x1F, 0x19},
	{0x1F, 0x1A},
	{0x1E, 0x1C},
	{0x1F, 0x1B},
	{0x1F, 0x1B},
	{0x1F, 0x1B},
	{0x1F, 0x1C},
	{0x1F, 0x1C},
	{0x1F, 0x1C},
	{0x1F, 0x1D},
	{0x1F, 0x1D},
	{0x1F, 0x1D},
	{0x1F, 0x1E},
	{0x1F, 0x1E},
	{0x1F, 0x1F},
	{0x1F, 0x1F},
};

#if __CUDACC__
__constant__ unsigned short
#else
const static uint8
#endif
OMatch6[256][2] =
{
	{0x00, 0x00},
	{0x00, 0x01},
	{0x01, 0x00},
	{0x01, 0x00},
	{0x01, 0x01},
	{0x02, 0x00},
	{0x02, 0x00},
	{0x02, 0x01},
	{0x03, 0x00},
	{0x03, 0x01},
	{0x04, 0x00},
	{0x04, 0x00},
	{0x04, 0x01},
	{0x05, 0x00},
	{0x05, 0x00},
	{0x05, 0x01},
	{0x06, 0x00},
	{0x06, 0x01},
	{0x07, 0x00},
	{0x07, 0x00},
	{0x07, 0x01},
	{0x08, 0x00},
	{0x00, 0x10},
	{0x08, 0x01},
	{0x09, 0x00},
	{0x09, 0x01},
	{0x01, 0x11},
	{0x0A, 0x00},
	{0x0A, 0x01},
	{0x0B, 0x00},
	{0x03, 0x10},
	{0x0B, 0x01},
	{0x0C, 0x00},
	{0x0C, 0x01},
	{0x04, 0x11},
	{0x0D, 0x00},
	{0x0D, 0x01},
	{0x0E, 0x00},
	{0x06, 0x10},
	{0x0E, 0x01},
	{0x0F, 0x00},
	{0x0F, 0x01},
	{0x07, 0x11},
	{0x10, 0x00},
	{0x0F, 0x03},
	{0x10, 0x01},
	{0x11, 0x00},
	{0x11, 0x01},
	{0x0F, 0x06},
	{0x12, 0x00},
	{0x12, 0x01},
	{0x13, 0x00},
	{0x0F, 0x09},
	{0x13, 0x01},
	{0x14, 0x00},
	{0x14, 0x01},
	{0x0F, 0x0C},
	{0x15, 0x00},
	{0x15, 0x01},
	{0x16, 0x00},
	{0x0F, 0x0F},
	{0x16, 0x01},
	{0x17, 0x00},
	{0x17, 0x01},
	{0x0F, 0x12},
	{0x18, 0x00},
	{0x18, 0x01},
	{0x19, 0x00},
	{0x11, 0x10},
	{0x19, 0x01},
	{0x1A, 0x00},
	{0x1A, 0x01},
	{0x12, 0x11},
	{0x1B, 0x00},
	{0x1B, 0x01},
	{0x1C, 0x00},
	{0x14, 0x10},
	{0x1C, 0x01},
	{0x1D, 0x00},
	{0x1D, 0x01},
	{0x15, 0x11},
	{0x1E, 0x00},
	{0x1E, 0x01},
	{0x1F, 0x00},
	{0x17, 0x10},
	{0x1F, 0x01},
	{0x1F, 0x02},
	{0x20, 0x00},
	{0x20, 0x01},
	{0x21, 0x00},
	{0x1F, 0x05},
	{0x21, 0x01},
	{0x22, 0x00},
	{0x22, 0x01},
	{0x1F, 0x08},
	{0x23, 0x00},
	{0x23, 0x01},
	{0x24, 0x00},
	{0x1F, 0x0B},
	{0x24, 0x01},
	{0x25, 0x00},
	{0x25, 0x01},
	{0x1F, 0x0E},
	{0x26, 0x00},
	{0x26, 0x01},
	{0x27, 0x00},
	{0x1F, 0x11},
	{0x27, 0x01},
	{0x28, 0x00},
	{0x28, 0x01},
	{0x20, 0x11},
	{0x29, 0x00},
	{0x29, 0x01},
	{0x2A, 0x00},
	{0x22, 0x10},
	{0x2A, 0x01},
	{0x2B, 0x00},
	{0x2B, 0x01},
	{0x23, 0x11},
	{0x2C, 0x00},
	{0x2C, 0x01},
	{0x2D, 0x00},
	{0x25, 0x10},
	{0x2D, 0x01},
	{0x2E, 0x00},
	{0x2E, 0x01},
	{0x26, 0x11},
	{0x2F, 0x00},
	{0x2F, 0x01},
	{0x2F, 0x02},
	{0x30, 0x00},
	{0x30, 0x01},
	{0x2F, 0x04},
	{0x31, 0x00},
	{0x31, 0x01},
	{0x32, 0x00},
	{0x2F, 0x07},
	{0x32, 0x01},
	{0x33, 0x00},
	{0x33, 0x01},
	{0x2F, 0x0A},
	{0x34, 0x00},
	{0x34, 0x01},
	{0x35, 0x00},
	{0x2F, 0x0D},
	{0x35, 0x01},
	{0x36, 0x00},
	{0x36, 0x01},
	{0x2F, 0x10},
	{0x37, 0x00},
	{0x37, 0x01},
	{0x38, 0x00},
	{0x30, 0x10},
	{0x38, 0x01},
	{0x39, 0x00},
	{0x39, 0x01},
	{0x31, 0x11},
	{0x3A, 0x00},
	{0x3A, 0x01},
	{0x3B, 0x00},
	{0x33, 0x10},
	{0x3B, 0x01},
	{0x3C, 0x00},
	{0x3C, 0x01},
	{0x34, 0x11},
	{0x3D, 0x00},
	{0x3D, 0x01},
	{0x3E, 0x00},
	{0x36, 0x10},
	{0x3E, 0x01},
	{0x3F, 0x00},
	{0x3F, 0x01},
	{0x37, 0x11},
	{0x3F, 0x02},
	{0x3F, 0x03},
	{0x3F, 0x04},
	{0x39, 0x10},
	{0x3F, 0x05},
	{0x3F, 0x06},
	{0x3F, 0x07},
	{0x3A, 0x11},
	{0x3F, 0x08},
	{0x3F, 0x09},
	{0x3F, 0x0A},
	{0x3C, 0x10},
	{0x3F, 0x0B},
	{0x3F, 0x0C},
	{0x3F, 0x0D},
	{0x3D, 0x11},
	{0x3F, 0x0E},
	{0x3F, 0x0F},
	{0x36, 0x21},
	{0x3F, 0x10},
	{0x3F, 0x11},
	{0x3F, 0x12},
	{0x38, 0x20},
	{0x3F, 0x13},
	{0x3F, 0x14},
	{0x3F, 0x15},
	{0x39, 0x21},
	{0x3F, 0x16},
	{0x3F, 0x17},
	{0x3F, 0x18},
	{0x3B, 0x20},
	{0x3F, 0x19},
	{0x3F, 0x1A},
	{0x3F, 0x1B},
	{0x3C, 0x21},
	{0x3F, 0x1C},
	{0x3F, 0x1D},
	{0x3F, 0x1E},
	{0x3E, 0x20},
	{0x3F, 0x1F},
	{0x3F, 0x20},
	{0x37, 0x30},
	{0x3F, 0x21},
	{0x3F, 0x22},
	{0x3F, 0x23},
	{0x38, 0x31},
	{0x3F, 0x24},
	{0x3F, 0x25},
	{0x3F, 0x26},
	{0x3A, 0x30},
	{0x3F, 0x27},
	{0x3F, 0x28},
	{0x3F, 0x29},
	{0x3B, 0x31},
	{0x3F, 0x2A},
	{0x3F, 0x2B},
	{0x3F, 0x2C},
	{0x3D, 0x30},
	{0x3F, 0x2D},
	{0x3F, 0x2E},
	{0x3F, 0x2F},
	{0x3E, 0x31},
	{0x3F, 0x30},
	{0x3F, 0x31},
	{0x3F, 0x31},
	{0x3F, 0x32},
	{0x3F, 0x33},
	{0x3F, 0x34},
	{0x3F, 0x34},
	{0x3F, 0x35},
	{0x3F, 0x36},
	{0x3F, 0x37},
	{0x3F, 0x37},
	{0x3F, 0x38},
	{0x3F, 0x39},
	{0x3F, 0x3A},
	{0x3F, 0x3A},
	{0x3F, 0x3B},
	{0x3F, 0x3C},
	{0x3F, 0x3D},
	{0x3F, 0x3D},
	{0x3F, 0x3E},
	{0x3F, 0x3F},
};

